<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <!-- 放置表单 -->
            <el-form ref="edformData" label-width="120px" style="margin-left: 120px; margin-top:30px" :model="formData" :rules="rules">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="formData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password2">
                <el-input v-model="formData.password2" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click.native="uploademployees">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <component :is="userInfoName" />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <component :is="jonInfoName" />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getemployees, uploademployees } from '@/api/employees'
import jonInfo from './jonInfo'
import userInfo from './userInfo'
export default {
  components: {
    jonInfo, userInfo
  },
  data() {
    return {
      jonInfoName: jonInfo,
      userInfoName: userInfo,
      departs: {},
      formData: {
        username: '',
        password2: ''
      },
      rules: {
        username: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        password2: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getemployees()
    console.log(this.userInfoName)
  },
  methods: {
    async getemployees() {
      this.formData = await getemployees(this.$route.params.id)

      // this.formData.password2 = password
      // console.log(username, password)
    },
    async uploademployees() {
      await this.$refs.edformData.validate()
      console.log(this.formData)
      await uploademployees({ ...this.formData.username, password: this.formData.password2 })
      this.$message.success('更新成功')
    }
  }
}
</script>
<style lang='less' scoped>

</style>
